<?php
class M_Users extends Model{

    public function M_Users(){
        parent::Model();
    }

    public function mCheckUser($sLogin,$sPasswd){
        $sQuery = " SELECT count(*) as cnt ";
        $sFrom  = " FROM utilizatori ";
        $sWhere = " WHERE user  = '".$sLogin."'"
                 ."   AND pass = '".$sPasswd."'";
                 
        log_message("debug","Checking user with sql:".$sQuery.$sFrom.$sWhere);         
        $query = $this->db->query($sQuery.$sFrom.$sWhere);
        $count = $query->result_array();
		$query->num_rows = $count[0]["cnt"];	
        if ($query->num_rows == 1){
			log_message('debug',"Check login for $sLogin is: OK");
			return true;
		}
		log_message('debug',"Check login for $sLogin is: KO");
		return false;
    }
  	public function mCheckUserDetails($sLogin,$sPasswd){
        $sQuery = " SELECT
						utilizatori.ID as id,
						utilizatori.name as name,
						utilizatori.surname as surname,
						utilizatori.cnp as CNP,
						utilizatori.COMPANY_ID as company,
						ll_references.R_CODE AS level
					 ";
        $sFrom  = " FROM utilizatori LEFT JOIN `ll_references` ON utilizatori.FK_LVL = `ll_references`.ID";
        $sWhere = " WHERE user  = '".$sLogin."'"
                 ." AND pass = '".$sPasswd."'";
                 
        log_message("debug","Checking user with sql:".$sQuery.$sFrom.$sWhere);         
        $query = $this->db->query($sQuery.$sFrom.$sWhere);
        $data = array();
        foreach($query->result() as $row){
        	$data["us_I"] = $row->id;
        	$data["us_N"] = $row->name." ".$row->surname;
        	$data["us_L"] = $row->level;
        	$data["us_S"] = $row->CNP;
			$data["us_C"] = $row->company;
        }
		return $data;
  	}	
 		
}
?>